package com.google.android.apps.wakemewhere;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;

public class Alarms {

    public static final Uri CONTENT_URI = Uri.parse("content://com.google.android.apps.wakemewhere/alarm");
    
    public static Alarm getAlarm(ContentResolver contentResolver, Uri uri) {
    	Cursor cursor = contentResolver.query(uri, 
    			AlarmDatabase.QUERY_COLUMNS, null, null, null);
    	if (cursor == null) {
    		return null;
    	}
    	
    	if (!cursor.moveToFirst()) {
    		return null;
    	}
    	
    	Alarm alarm = new Alarm(cursor);
    	cursor.close();
    	return alarm;    	
    }
	
	public static Alarm getAlarm(ContentResolver contentResolver, long alarmId) {
		return getAlarm(contentResolver, uriForId(alarmId));
	}
		
	public static Uri uriForId(long id) {
		return ContentUris.withAppendedId(CONTENT_URI, id);
	}
}
